package kino.command;

import kino.client.KinoClient;
import kino.database.KinoDB;
import kino.object.KinoObject;

import java.util.Map;

@KinoCommandEnable
public class TypeCommand extends AbstractKinoCommand{
    @Override
    public String doExecute(KinoClient client, String... argv) {
        KinoDB db = client.getDb();
        Map<String, KinoObject> dict = db.getDict();
        String key = argv[0];
        if (dict.containsKey(key)) {
            KinoObject object = dict.get(key);
            switch (object.getType()) {
                case KINO_STRING:
                    return commandEncoder.simpleStringEncode("string");
                case KINO_HASH:
                    return commandEncoder.simpleStringEncode("hash");
                case KINO_LIST:
                    return commandEncoder.simpleStringEncode("list");
                case KINO_SET:
                    return commandEncoder.simpleStringEncode("set");
                case KINO_ZSET:
                    return commandEncoder.simpleStringEncode("zset");
                default:
                    return commandEncoder.simpleStringEncode("none");
            }
        }
        return commandEncoder.simpleStringEncode("none");
    }

    @Override
    public Integer getArgc() {
        return 1;
    }

    @Override
    public String getCommandName() {
        return "type";
    }

    @Override
    public boolean aofFlag() {
        return false;
    }

    @Override
    public boolean hasExtParam() {
        return false;
    }
}
